package com.wewins.fota.bean.bo;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.List;

@Data
public class RedisLuaResp {
    private String rstList;
    private String rstObj;
    private String rstStr;

    public <T> List<T> parseRstList(Class<T> clazz) {
        if (StringUtils.isEmpty(rstList) || !rstList.startsWith("[") || !rstList.endsWith("]")) {
            return null;
        }
        return JSON.parseArray(rstList, clazz);
    }

    public <T> T parseRstObj(Class<T> clazz) {
        if (StringUtils.isEmpty(rstObj) || !rstObj.startsWith("{") || !rstObj.endsWith("}")) {
            return null;
        }
        return JSON.parseObject(rstObj, clazz);
    }
}
